package cn.kstry.demo.config;

import cn.kstry.framework.core.bus.ScopeDataQuery;
import cn.kstry.framework.core.engine.thread.hook.ThreadSwitchHook;
import org.springframework.stereotype.Component;

@Component
public class SwitchHook implements ThreadSwitchHook<String> {

    public static final ThreadLocal<String> ITERATOR_THREAD_LOCAL = new ThreadLocal<>();

    @Override
    public String getPreviousData(ScopeDataQuery scopeDataQuery) {
        return ITERATOR_THREAD_LOCAL.get();
    }

    @Override
    public void usePreviousData(String data, ScopeDataQuery scopeDataQuery) {
        ITERATOR_THREAD_LOCAL.set(data);
    }
}
